package com.znsb.msfq.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.TextView;

import com.znsb.msfq.R;


//更新弹出框
public class UpAppDialog {

	private AlertDialog alertDialog = null;
	private Window window = null;
	private Context context = null;
	private String hitetext = null;
	private CallBackd callback = null;

	public interface CallBackd {
		public void click(View v);
	}

	// callback不能传空（this）
	public UpAppDialog(Context context, String hitetext) {
		super();
		this.context = context;
		this.hitetext = hitetext;
		initDialog();
	}

	private void initDialog() {
		alertDialog = new AlertDialog.Builder(context).create();
		alertDialog.show();
		window = alertDialog.getWindow();
		window.setContentView(R.layout.dialog_upapp);
		SetMessage(hitetext);
		// 取消
		window.findViewById(R.id.negativeButton).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						alertDialog.dismiss();
					}
				});
	}

	private void SetMessage(String hitetext) {
		((TextView) window.findViewById(R.id.text)).setText(hitetext);
	}

	public void isshow() {
		alertDialog.show();
	}

	public void isdismiss() {
		alertDialog.cancel();
	}

	// 设置弹出框位置
	public void SetDlocation(int gravity) {
		alertDialog.getWindow().setGravity(gravity);
	}

	// 设置弹出框坐标位置
	public void SetCoordinatePosition(int width, int height) {
		alertDialog.getWindow().setLayout(width, height);
	}
    //设置按钮的文字F
	public void SetKNOBtext(String positive, String negative) {
		if (TextUtils.isEmpty(negative)) {
			((TextView) window.findViewById(R.id.negativeButton))
					.setText(negative);
		}

	}
}
